<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <div>数量 <input id="goodsnum" /> </div>
        <div>价格 <input id="goodsprice" /> </div>
        <div>小计<span id="total"></span></div>
    </div>
</body>
<script>
    let goodsnumInput = document.getElementById("goodsnum");
    let goodspriceInput = document.getElementById("goodsprice");
    let totalSpan = document.getElementById("total");

    let info = {
    }
    var _n = 0;
    var _price = 0;
    Object.defineProperty(info, "num", {
        set(n) {
            _n = n;
            complied();
        },
        get() {
            return _n;

        }
    });
    Object.defineProperty(info, "price", {
        set(price) {
            _price = price;
            complied();
        },
        get() {
            return _price;

        }
    });
    function complied() {
        totalSpan.innerHTML = info.num * info.price;
    }
    goodsnumInput.oninput = function () {//只做了num的改变
        info.num = goodsnumInput.value;//修改了 对象的属性
    }
    goodspriceInput.oninput = function () {
        info.price = goodspriceInput.value;//给对象的属性赋值
    }

</script>

</html>